package ipdesk.model.businessInfo.action;

import ipdesk.model.businessInfo.bean.BusinessInfoBean;
import ipdesk.model.businessInfo.dao.BusinessInfoDao;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

import ecg.util.Time;


public class BusinessInfoRegAction extends ActionSupport implements Preparable, ModelDriven<BusinessInfoBean>
{
	
	private BusinessInfoBean businessInfoBean;
	private BusinessInfoBean businessInfoDetail;
	private BusinessInfoBean customerInfoDetail;
	
	@Override
	public String execute() throws Exception
	{
		/**
		 * 기업정보와 기업 담당자 정보를 저장하는 메서드.
		 */
		BusinessInfoDao.getInstance().businessInfoReg(businessInfoBean);
				
		return SUCCESS;
	}
	
	/**
	 * 기업 정보 수정 폼.
	 * @return
	 * @throws Exception
	 */
	public String executeModifyForm() throws Exception
	{
		/**
		 * 넘어온 companySeq를 조건으로 DB에서 데이터를 가져온다.
		 */
		int companySeq = businessInfoBean.getCompanySeq();
		
		businessInfoDetail = BusinessInfoDao.getInstance().getModifyData(companySeq);
		
		return SUCCESS;
	}
	
	/**
	 * 기업 정보 수정.
	 * @return
	 * @throws Exception
	 */
	public String executeModify() throws Exception
	{
		/**
		 * 	1. 넘어온 companySeq를 조건으로 업로드된 데이터가 있는지 여부를 확인한다.
		 */
		int companySeq = businessInfoBean.getCompanySeq();
		
		String modifyTime = Time.getDateTime();
		businessInfoBean.setModifyTime(modifyTime);
		
		// 공지사항 update
		int result = BusinessInfoDao.getInstance().companyUpdate(businessInfoBean);
		
		
		return SUCCESS;
	}
	
	
	/**
	 * 기업 정보 삭제 처리
	 * @return
	 * @throws Exception
	 */
	public String executeDelelete() throws Exception
	{
				
		BusinessInfoDao.getInstance().bizCompanyInfoDelete(businessInfoBean);
		
		return SUCCESS;
	}
	
	/**
	 * 담당자 정보 추가 등록
	 * @return
	 * @throws Exception
	 */
	public String executeCustomerAdd() throws Exception
	{
		BusinessInfoDao.getInstance().bizCustomerInfoReg(businessInfoBean);
		
		return SUCCESS;
	}
	
	
	/**
	 * 기업 담당자 정보 수정 폼.
	 * @return
	 * @throws Exception
	 */
	public String executeCustomerModifyForm() throws Exception
	{
		/**
		 * 넘어온 customerSeq를 조건으로 DB에서 데이터를 가져온다.
		 */
		int customerSeq = businessInfoBean.getCustomerSeq();
		
				
		customerInfoDetail = BusinessInfoDao.getInstance().getModifyCustomerData(customerSeq);
		
		return SUCCESS;
	}
	
	
	/**
	 * 담당자 정보 수정 처리
	 * @return
	 * @throws Exception
	 */
	public String executeCustomerModify() throws Exception
	{
		BusinessInfoDao.getInstance().bizCustomerInfoUpdate(businessInfoBean);
		
		return SUCCESS;
	}
	
	/**
	 * 담당자 정보 삭제 처리
	 * @return
	 * @throws Exception
	 */
	public String executeCustomerDelelete() throws Exception
	{
		
		BusinessInfoDao.getInstance().bizCustomerInfoDelete(businessInfoBean);
		
		return SUCCESS;
	}
	
	public BusinessInfoBean getBusinessInfoDetail()
	{
		return businessInfoDetail;
	}


	public void setBusinessInfoDetail(BusinessInfoBean businessInfoDetail)
	{
		this.businessInfoDetail = businessInfoDetail;
	}

	
	public BusinessInfoBean getCustomerInfoDetail()
	{
		return customerInfoDetail;
	}

	public void setCustomerInfoDetail(BusinessInfoBean customerInfoDetail)
	{
		this.customerInfoDetail = customerInfoDetail;
	}

	public void prepare() throws Exception
	{
		businessInfoBean = new BusinessInfoBean();
	}
	
	public BusinessInfoBean getModel()
	{
		return businessInfoBean;
	}
}
